// 管理账号信息
const USERINFO_KEY = 'USERINFO_KEY';
const SERVER_HOST_KEY = 'SERVER_HOST_KEY';
const PASSWORD_STORE_KEY = 'PASSWORD_STORE_KEY';
const DEVICE_TYPE_KEY = 'DEVICE_TYPE_KEY';

const getUser = function () {
    let ret = '';
    ret = uni.getStorageSync(USERINFO_KEY);
    if (!ret) {
        return '';
    }
    return JSON.parse(ret);
}

const setUser = function (account, password) {
    let userInfo = {
        account: account,
        password: password
    };console.log("setUser:" + JSON.stringify(userInfo));
    uni.setStorageSync(USERINFO_KEY, JSON.stringify(userInfo));
}

const getServerHost = function () {
	
	let ret = uni.getStorageSync(SERVER_HOST_KEY);
    if (!ret) {
        ret = 'https://easy-mock.com/mock/5c7fd5418cfae820245a9ab0/moa';
		ret = 'http://23j84760g2.qicp.vip';
    }
    return ret;
}

const setServerHost = function (serverHost) {
	uni.setStorageSync(SERVER_HOST_KEY, serverHost);
}

const getServerResponseErr = function (responseJS) {
	if (responseJS.error != 0) {
		return responseJS.errordesc;
	}
	return responseJS.error;
}

const getPasswordStoreEnable = function () {
	let ret = uni.getStorageSync(PASSWORD_STORE_KEY);
	return ret;
}

const setPasswordStoreEnable = function (isEnable) {
	let ret = uni.setStorageSync(PASSWORD_STORE_KEY, isEnable);
	return ret;
}

const getDeviceType = function () {
	let ret = uni.getStorageSync(DEVICE_TYPE_KEY);
	if (!ret) ret = 'Phone';
	return ret;
}

const setDeviceType = function (deviceType) {
	let ret = uni.setStorageSync(DEVICE_TYPE_KEY, deviceType);
	return ret;
}

export default {
    getUser,
    setUser,
	getServerHost,
	setServerHost,
	getServerResponseErr,
	getDeviceType,
	setDeviceType,
	getPasswordStoreEnable,
	setPasswordStoreEnable
}
